import { defineStore } from 'pinia'
export const useUserStore = defineStore('user', {
  state: () => {
    return {
      nickName: '',
      userAvatar: '',
      userId: ''
    }
  },
  persist: true,
  actions: {
    /**
     * 初始化user
     */
    async initUser () {
      const { data } = await http({
        url: '/p/user/userInfo',
        method: 'get'
      })
      this.nickName = data.nickName
      this.userAvatar = data.pic
      this.userId = data.userId
    },
    /**
     * 设置user
     * @param user
     */
    setUser (user) {
      this.nickName = user.nickName
      this.userAvatar = user.userAvatar
      this.userId = user.userId
    },
    /**
     * 清空信息
     */
    resetUser () {
      this.nickName = ''
      this.userAvatar = ''
      this.userId = ''
    }
  }
})
